package org.geektime.task.sbcachemanager.controller;

import org.geektime.task.sbcachemanager.bean.User;
import org.geektime.task.sbcachemanager.service.ICacheManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/cache")
public class CacheManagerController {


    @Autowired
    private ICacheManagerService cacheManagerService;


    @RequestMapping(value = "/getUserById")
    @ResponseBody
    public Map<String,Object> getUserById(String userId){
        Map<String,Object> rMap = new HashMap<String,Object>();
        if(userId == null || userId.trim().length() == 0){
            throw new RuntimeException("未指定参数");
        }
        User user = cacheManagerService.getUserById(userId);
        rMap.put("user",user);
        return rMap;

    }


    @RequestMapping(value = "/deleteUser")
    @ResponseBody
    public Map<String,Object> deleteUser(String userId){
        Map<String,Object> rMap = new HashMap<String,Object>();
        if(userId == null || userId.trim().length() == 0){
            throw new RuntimeException("未指定参数");
        }
        cacheManagerService.deleteUser(userId);
        rMap.put("user","ok");
        return rMap;

    }





}
